import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:niuren_demo/configs/App_style_config.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:niuren_demo/page/dynamic/contant/account_page.dart';
import 'package:niuren_demo/page/dynamic/contant/cDynamic_page.dart';
import 'package:niuren_demo/page/dynamic/contant/message_page.dart';
import 'package:niuren_demo/page/dynamic/contant/team_page.dart';
import 'package:niuren_demo/page/dynamic/contant/transaction_page.dart';
import 'package:niuren_demo/page/dynamic/edit_page.dart';
import 'package:niuren_demo/view/StickyTabBarDelegate.dart';
import 'package:niuren_demo/view/text/text_style.dart';

class DynamicPage extends StatefulWidget {
  @override
  _DynamicPageState createState() => _DynamicPageState();
}

class _DynamicPageState extends State<DynamicPage>
with SingleTickerProviderStateMixin{
  List<String> tabTitles = ["账户", "交易", "动态","团队", "消息"];
  List<Tab> tabList = [];
  List<Widget> pages = [
    AccountPage(),
    TransactionPage(),
    cDynamicPage(),
    TeamPage(),
    MessagePage()
  ];

  TabController mController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    mController = TabController(
      length: tabList.length,
      vsync: this,
    );

    tabTitles.forEach((title) {
      tabList.add(Tab(
        text: title,
      ));
    });
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: tabList.length,
      child: Scaffold(
        backgroundColor: AppStyleConfig.themColor,
        body: NestedScrollView(
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            return [
              buildSliverAppBar(),
              buildSliverPersistenHeader(),
            ];
          },
          body: TabBarView(
            // controller: mController,
            children: pages,
          ),
        ),
      ),
    );
  }

  Widget buildSliverAppBar() {
    return SliverAppBar(
      backgroundColor: AppStyleConfig.themColor,
      pinned: true, //title固定在顶部不会滑动出屏幕
      expandedHeight: 218,
      actions: [
        IconButton(
            icon: Icon(
              Icons.edit_location_sharp,
              color: Colors.white,
            ),
            onPressed: () {})
      ],
      flexibleSpace: FlexibleSpaceBar(background: buildprofile()),
    );
  }
  // 个人介绍
  Widget buildprofile() {
    return Container(
      decoration: BoxDecoration(
          image: DecorationImage(
              fit: BoxFit.fill,
              image: NetworkImage(
                "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202004%2F12%2F20200412095043_mcups.jpg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1618562336&t=b33963960406af202b532b051943cb00",
              ))),
      padding: EdgeInsets.fromLTRB(20, 20, 20, 60),
      child: Column(
        children: [
          GestureDetector(
            onTap: ()=>Get.to(EditPage()),
            child: Container(
              width: 50,
              height: 50,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(50),
                image: DecorationImage(
                  image: NetworkImage(
                    "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201808%2F15%2F20180815112431_keyzi.thumb.700_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1617851642&t=7b6a7c66ce19ae61adcdf25c8c3b8856",
                  ),
                ),
              ),
            ),
          ),
          SizedBox(
            height: 10,
          ),
          Text_style(
            data: "陈大牛",
            fontSize: 18,
            weight: FontWeight.bold,
            color: Colors.white,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text_style(
                data: "男/广东珠海",
                color: Colors.white,
                fontSize: 13,
              ),
              Container(
                width: 16,
                height: 16,
                child: Image(
                  image: AssetImage("images/logo.png"),
                ),
              )
            ],
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            child: Text_style(
              data:
                  "一句话的个人简介或签名，最多两行显示超出省略号表示。一句话的个人简介或签名，最多两行显示超出省略号表示。一句话的个人简介或签名，最多两行显示超出省略号表示。",
              maxLines: 2,
              overflow: TextOverflow.ellipsis,
              color: Colors.white,
              fontSize: 13,
            ),
          )
        ],
      ),
    );
  }

  Widget buildSliverPersistenHeader() {
    return SliverPersistentHeader(
      // pinned: true,
      delegate: StickyTabBarDelegate(
        child: TabBar(
          indicator: const BoxDecoration(),
          labelColor: Colors.black,
          labelStyle: TextStyle(fontWeight: FontWeight.bold),
          unselectedLabelColor: Colors.grey,
          tabs: tabList,
        ),
      ),
    );
  }
}
